package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabFinanceSettleDetail;
import com.ysd.lis.mapper.lab.LabFinanceSettleDetailMapper;
import com.ysd.lis.request.lab.FinanceSettleDto;
import com.ysd.lis.service.lab.LabFinanceSettleDetailService;
import com.ysd.util.ToolsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 通道号管理表 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-10-29
 */
@Service
public class LabFinanceSettleDetailServiceImpl extends ServiceImpl<LabFinanceSettleDetailMapper, LabFinanceSettleDetail> implements LabFinanceSettleDetailService {

    @Autowired
    LabFinanceSettleDetailMapper labFinanceSettleDetailMapper;

    @Override
    public Result findFinanceSettleDetailList(FinanceSettleDto param) {
        String settleNo = param.getSettleNo();
//        if (StringUtils.isEmpty(settleNo)) {
//            return Result.succ(1, "申请编号为空", "");
//        }
        MPJLambdaWrapper<LabFinanceSettleDetail> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(LabFinanceSettleDetail.class);
//        queryWrapper.selectAs("lic", LabReqMain::getPatNo, LabFinanceSettleReq::getPatNo);
//        queryWrapper.selectAs("lic", LabReqMain::getPatNa, LabFinanceSettleReq::getPatNa);
//        queryWrapper.selectAs("lic", LabReqMain::getReqPurpose, LabFinanceSettleReq::getReqPurpose);

        //queryWrapper.leftJoin(LabReqMain.class, "lic", p -> p.eq(LabReqMain::getReqNo, LabFinanceSettleDetail::getReqNo).eq(LabReqMain::getDelFlag, 0));

        queryWrapper.eq(LabFinanceSettleDetail::getDelFlag, 0);
        if (ToolsUtils.isNotEmpty(settleNo)) {
            queryWrapper.eq(LabFinanceSettleDetail::getSettleNo, settleNo);
        }
        if (ToolsUtils.isNotEmpty(param.getSettleId())) {
            queryWrapper.eq(LabFinanceSettleDetail::getSettleId, param.getSettleId());
        }
        if (ToolsUtils.isNotEmpty(param.getSettleNoes())) {
            String[] split = param.getSettleNoes().split(",");
            queryWrapper.in(LabFinanceSettleDetail::getSettleNo, Arrays.stream(split).collect(Collectors.toList()));
        }
        List<LabFinanceSettleDetail> settleReqList = labFinanceSettleDetailMapper.selectList(queryWrapper);
        return Result.succ(1, "查询成功!", settleReqList);
    }
}
